babl-cache: Add a #define for FALLBACK_CACHE_PATH
authorEdward E <develinthedetail@gmail.com>
Tue, 22 Nov 2016 19:50:34 +0000 (20:50 +0100)
committerØyvind Kolås <pippin@gimp.org>
Tue, 22 Nov 2016 19:53:08 +0000 (20:53 +0100)
Also return fallback cache path if failing to create location for constructed
path.

NEWS
babl/babl-cache.c

diff --git a/NEWS b/NEWS
index 4648db8988ed33add5f2da1365141aa4dc96a371..a885050d816553768b5dd07adf79cffd9c1cee6d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,10 @@ the news section both in the README and the webpage.
 
 
                                                                           -->
+2016-11-05 babl-0.1.22                                              </dt><dd>
+Added cache of profiled conversions, added HCY color model, some precision and
+performance updated for fast paths.
+                                                                    </dd><dt>
 2016-11-05 babl-0.1.20                                              </dt><dd>
 Fix run-time errors, leaks, and race conditions. Add conditional fast paths.
                                                                     </dd><dt>
index 5d1921681d66db715c8a0ec72e67f544c7f2edad..db8c3b54cdde1e7b52bd0f910dab302b0d180921 100644 (file)
 #include "babl-internal.h"
 #include "git-version.h"
 
+#ifdef _WIN32
+#define FALLBACK_CACHE_PATH  "C:/babl-fishes.txt"
+#else
+#define FALLBACK_CACHE_PATH  "/tmp/babl-fishes.txt"
+#endif
+
 static int
 mk_ancestry_iter (const char *path)
 {
@@ -64,26 +70,24 @@ mk_ancestry (const char *path)
 static const char *fish_cache_path (void)
 {
   struct stat stat_buf;
-  static char resolved[4096];
+  static char path[4096];
 
+  strncpy (path, FALLBACK_CACHE_PATH, 4096);
 #ifndef _WIN32 
   if (getenv ("HOME"))
-    sprintf (resolved, "%s/.cache/babl/babl-fishes", getenv("HOME"));
-  else
-    strncpy (resolved, "/tmp/babl.db", 4096);
+    sprintf (path, "%s/.cache/babl/babl-fishes", getenv("HOME"));
 #else
   if (getenv ("TEMP"))
-    sprintf (resolved, "%s\\babl-fishes.txt", getenv("TEMP"));
-  else
-    strncpy (resolved, "c:\\babl-fishes.txt", 4096);
+    sprintf (path, "%s\\babl-fishes.txt", getenv("TEMP"));
 #endif
 
-  if (stat (resolved, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))
-    return resolved;
+  if (stat (path, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))
+    return path;
 
-  mk_ancestry (resolved);
+  if (mk_ancestry (path) != 0)
+    return FALLBACK_CACHE_PATH;
 
-  return resolved;
+  return path;
 }
 
 static char *